package zj.it.bhne.gridengineeringsurvey.fragment.details;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import zj.it.bhne.gridengineeringsurvey.R;
import zj.it.bhne.gridengineeringsurvey.activity.DetailsActivity;
import zj.it.bhne.gridengineeringsurvey.entity.greendao.Items;
import zj.it.bhne.gridengineeringsurvey.MyApplication;
import zj.it.bhne.gridengineeringsurvey.myutils.greendao.ItemsDao;


/**
 * 本地項目詳情中的fragment
 */
public class BasisFragment extends Fragment {

    private int cid;

    /**
     * 基础信息
     */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        assert getArguments() != null;
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_basis, container, false);
        initView(view);
        /*assert getArguments() != null;
        cid = getArguments().getInt("DATA");*/
        return view;
    }

    private void initView(View view) {
        TextView add_tv_time = view.findViewById(R.id.add_tv_time);
        TextView ba_tv_name = view.findViewById(R.id.ba_tv_name);
        TextView ba_tv_dengji = view.findViewById(R.id.ba_tv_dengji);
        TextView ba_tv_leixing = view.findViewById(R.id.ba_tv_leixing);
        TextView ba_tv_gaizao = view.findViewById(R.id.ba_tv_gaizao);
        List<Items> itemsList = MyApplication.getInstances().getItemsDao().queryBuilder().where(ItemsDao.Properties.Id.eq(DetailsActivity.DATA)).build().list();
        if (itemsList.size() > 0) {
            ba_tv_name.setText(itemsList.get(0).getName());
            add_tv_time.setText(itemsList.get(0).getTime());
            ba_tv_dengji.setText(itemsList.get(0).getVoltage());
            ba_tv_gaizao.setText(itemsList.get(0).getNote());
            ba_tv_leixing.setText(itemsList.get(0).getType());
        }
    }
}
